// 1. 引入mock.js
import Mock from 'mockjs'
// 获取mock.Random 对象
const Random = Mock.Random

// 导航菜单树结构（用来渲染左边导航菜单的数据源）
// 不同的用户登录有不同的导航菜单
let menusList = [
  {
    id: 1,
    name: 'dashboard',
    icon: 'icon',
    num: '1',
    route: "/admin/dashboard",
    type: 'menu',
    status: '显示'
  },
  {
    id: 2,
    name: '栏目管理',
    icon: "icon_6",
    num: '2',
    route: "/admin/category",
    type: 'menu',
    status: '显示'  // 或者隐藏
  },
  {
    id: 3,
    name: '产品管理',
    icon: "icon_16",
    num: '3',
    route: "/admin/product",
    type: 'menu',
    status: '显示'
  },
  {
    id: 4,
    name: '账单管理',
    icon: "icon_14",
    num: '4',
    route: "/admin/account",
    type: 'menu',
    status: '显示',
    children: [
      {
        id: 5,
        name: '顾客账单',
        num: '5',
        route: "/admin/account/custome",
        type: 'menu',
        status: '显示'
      },
      {
        id: 6,
        name: '员工账单',
        num: '6',
        route: "/admin/account/employee",
        type: 'menu',
        status: '显示'
      }
    ]
  },
  {
    id: 7,
    name: "订单管理",
    num: '7',
    icon: 'icon_10',
    route: "/admin/ordermanager",
    type: 'menu',
    status: '显示'
  },
  {
    id: 8,
    name: "审核大厅",
    num: '8',
    icon: 'icon_13',
    route: "/admin/check",
    type: 'menu',
    status: '显示',
    children: [
      {
        id: 9,
        name: '实名认证',
        num: '9',
        route: "/admin/check/certification",
        type: 'menu',
        status: '显示'
      },
      {
        id: 10,
        name: '账户变更',
        num: '10',
        route: "/admin/check/accountApply",
        type: 'menu',
        status: '显示'
      },
      {
        id: 11,
        name: '资讯评论',
        num: '11',
        route: "/admin/check/infoComment",
        type: 'menu',
        status: '显示'
      },
      {
        id: 12,
        name: '订单评论',
        num: '12',
        route: "/admin/check/orderComment",
        type: 'menu',
        status: '显示'
      }
    ]
  },
  {
    id: 13,
    name: '顾客管理',
    num: '13',
    icon: 'icon_9',
    route: '/admin/custome',
    type: 'menu',
    status: '显示'
  },
  {
    id: 14,
    name: '员工管理',
    num: '14',
    icon: 'icon_4',
    route: '/admin/waiter',
    type: 'menu',
    status: '显示'
  },
  {
    id: 15,
    name: '网站资讯',
    num: '15',
    icon: 'icon_1',
    route: '/admin/info',
    type: 'menu',
    status: '显示',
    children: [
      {
        id: 16,
        name: '资讯信息',
        num: '16',
        route: '/admin/info/list',
        type: 'menu',
        status: '显示'
      },
      {
        id: 17,
        name: '资讯详情',
        num: '17',
        route: '/admin/info/details',
        type: 'menu',
        status: '显示'
      },
      {
        id: 18,
        name: '发布资讯',
        num: '18',
        route: '/admin/info/publish',
        type: 'menu',
        status: '显示'
      },
      {
        id: 19,
        name: '资讯分类',
        num: '19',
        route: '/admin/info/category',
        type: 'menu',
        status: '显示'
      },
    ]
  },
  {
    id: 20,
    name: '角色权限',
    num: '20',
    icon: 'icon_2',
    route: '/admin/sys',
    type: 'menu',
    status: '显示',
    children: [
      {
        id: 21,
        name: '用户管理',
        num: '21',
        route: '/admin/sys/user',
        type: 'menu',
        status: '显示'
      },
      {
        id: 22,
        name: '用户详情',
        num: '22',
        route: '/admin/sys/userDetails',
        type: 'menu',
        status: '显示'
      },
      {
        id: 23,
        name: '角色管理',
        num: '23',
        route: '/admin/sys/role',
        type: 'menu',
        status: '显示'
      },
      {
        id: 24,
        name: '权限管理',
        num: '24',
        route: '/admin/sys/privilege',
        type: 'menu',
        status: '显示'
      },
    ]
  },
  {
    id: 25,
    name: '轮播管理',
    num: '25',
    icon: 'icon_8',
    route: '/admin/carousel',
    type: 'menu',
    status: '显示',
  },
  {
    id: 26,
    name: '日志管理',
    num: '26',
    icon: 'icon_17',
    route: '/admin/log',
    type: 'menu',
    status: '显示'
  },
  {
    id: 27,
    name: '系统配置',
    num: '27',
    icon: 'icon_5',
    route: '/admin/baseConfig',
    type: 'menu',
    status: '显示'
  },
  {
    id: 28,
    name: '个人信息',
    num: '28',
    icon: 'icon_3',
    route: '/admin/ownerIndex',
    type: 'menu',
    status: '显示'
  }
]
// 获取导航数据
Mock.mock('/menus/list', 'get', options => {
  return {
    status: 2000,
    message: '获取成功',
    data: menusList
  }
})
// 添加导航菜单
let index = menusList.length - 1
let lastId = menusList[index].id
Mock.mock('/menus/add', 'post', options => {
  let params = JSON.parse(options.body)
  // 如果有子菜单加上children 前端传递的值为一个数组
  const [name, icon, route, type, status] = [params.name, params.icon, params.route, params.type, params.status]
  let obj = {
    id: lastId + 1,
    name: name,
    num: lastId + 1,
    icon: icon,
    route: route,
    type: type,
    status: status
  }
  menusList.push(obj)
  return {
    status: 2000,
    message: '添加成功'
  }
})
// 导航菜单不能随意删除及添加


// 用户列表
//#region 
const userlist = [
  { id: 1, username: 'briup', password: 'briup123', realName: Random.cname(), date: Random.date() + ' ' + Random.time() },
  { id: 2, username: 'user', password: 'user123', realName: Random.cname(), date: Random.date() + ' ' + Random.time() },
  { id: 3, username: 'admin1', password: '123321', realName: Random.cname(), date: Random.date() + ' ' + Random.time() },
]
// 拦截登录的请求  axios
// http://47.100.65.29:8002/user/login  /user/userlist /user/userinfo?id=1
Mock.mock('/user/login', 'post', (options) => {
  let params = JSON.parse(options.body)
  for (let i = 0; i < userlist.length; i++) {
    if (params.username === userlist[i].username && params.password === userlist[i].password) {
      return {
        status: 2000,
        message: '登录成功',
        token: 'wqe123safasd123353gasdasad12313'
      }
    }
  }
  return {
    status: 1001,
    message: '登录失败,用户名或密码错误'
  }
})

// 获取用户详情
Mock.mock('/user/info', 'get', options => {
  let id = JSON.parse(options.body).id
  let userData = userlist.filter(i => i.id == id)
  return {
    status: 2000,
    data: userData,
    message: '获取成功'
  }
})
//#endregion

// 栏目列表
//#region 
// 栏目名称
let categoryNames = [
  "环境治理",
  "家电清洗",
  "衣物护理",
  "家具养护",
  "母婴陪护"
]
let { categoryDatas } = Mock.mock({
  "categoryDatas|20-30": [  // | 20-30 随机生成20-30条数据
    {
      "id|+1": 1, //id自增
      "cateName|+1": 9001, //
      "name|1": categoryNames, // 从栏目名称中随机获取一个
      "icon": Random.image('20x20', "#d8d8d8", '#fff', 'mock'),
      "sortId|+1": 2001,
      "date": Random.date() + ' ' + Random.time()
    }
  ]
})
// 分页请求栏目列表数据
Mock.mock('/category/list', 'post', options => {
  const [pageSize, pageNum, total] = [JSON.parse(options.body).pageSize, JSON.parse(options.body).pageNum, categoryDatas.length]
  let len = total / pageSize
  //总页数
  const totalPages = len - parseInt(len) > 0 ? parseInt(len) + 1 : len
  // 截取categoryDatas
  const newDatas = categoryDatas.slice((pageNum - 1) * pageSize, pageNum * pageSize)
  return {
    status: 2000,
    message: '获取数据成功',
    data: {
      list: newDatas,
      total: total,
    }
  }
})

// 添加栏目
Mock.mock('/category/add', 'post', options => {
  if (categoryNames.indexOf(JSON.parse(options.body).name) !== -1) {
    return {
      status: 2001,
      message: '该栏目已存在'
    }
  }
  let obj = {
    id: categoryDatas.length,
    cateName: categoryDatas[categoryDatas.length - 1].cateName + 1,
    name: JSON.parse(options.body).name,
    icon: Random.image('20x20', "#d8d8d8", '#fff', 'mock'),
    sortId: categoryDatas[categoryDatas.length - 1].sortId + 1,
    date: Random.date() + ' ' + Random.time()
  }
  categoryNames.push(JSON.parse(options.body).name)
  categoryDatas.unshift(obj)
  let cate = {
    value: JSON.parse(options.body).name,
    label: JSON.parse(options.body).name
  }
  includeList.push(cate)
  return {
    status: 2000,
    message: '添加成功!'
  }
})

// 删除栏目
Mock.mock('/category/del', 'post', options => {
  let id = JSON.parse(options.body)
  let newDatalist = categoryDatas.filter(i => i.id !== id);
  let removeData = categoryDatas.filter(i => i.id == id)
  categoryNames = categoryNames.slice(removeData.name)
  categoryDatas = newDatalist
  return {
    status: 2000,
    message: '删除成功'
  }
})
//#endregion

// 订单相关页面
//#region 
let orderList = []
for (let i = 0; i < 30; i++) {
  let obj = {
    id: i + 1,
    orderNum: Random.natural(9000, 10000), //随机生成 xx-xx 之间的数
    orderTime: Random.date() + ' ' + Random.time(), // 随机生成中文名 
    price: Random.natural(200, 500),
    status: '待派单',
    customId: Random.natural(100, 200),
    employeeId: Random.natural(1, 100),
  }
  orderList.push(obj)
}
// 分页获取所有订单数据
Mock.mock('/order/list', 'post', options => {
  const [pageSize, pageNum, total] = [JSON.parse(options.body).pageSize, JSON.parse(options.body).pageNum, orderList.length]
  let len = total / pageSize
  //总页数
  const totalPages = len - parseInt(len) > 0 ? parseInt(len) + 1 : len
  // 截取
  const newDatas = orderList.slice((pageNum - 1) * pageSize, pageNum * pageSize)
  return {
    status: 2000,
    message: '获取数据成功',
    data: {
      list: {
        tableHeader: { orderNum: '订单编号', orderTime: '下单时间', price: '总价', status: '状态', customId: '顾客ID', employeeId: '员工ID' },
        tableData: newDatas
      },
      total: total,
    }
  }
})
// 派单的方法
Mock.mock('/order/sendOrder', 'post', options => {
  let id = options.body
  for (let index = 0; index < orderList.length; index++) {
    if (orderList[index].id == id) {
      orderList[index].status = '待接单'
    }
  }
  return {
    status: 2000,
    message: '派单成功'
  }
})
// 取消派单
Mock.mock('/order/resetOrder', 'post', options => {
  let id = options.body
  for (let index = 0; index < orderList.length; index++) {
    if (orderList[index].id == id) {
      orderList[index].status = '待派单'
    }
  }
  return {
    status: 2000,
    message: '取消派单'
  }
})
//#endregion

// 产品管理相关的接口
//#region 
let productList = []
const includeList = []
for (let i = 0; i < categoryNames.length; i++) {
  let obj = {
    value: categoryNames[i],
    label: categoryNames[i],
  }
  includeList.push(obj)
}
// 获取栏目名称
function getInclude() {
  return includeList[Random.natural(0, includeList.length - 1)].label
}
for (let i = 0; i < 33; i++) {
  let obj = {
    id: i + 1,
    productNum: Random.natural(9000, 10000), //产品编号 随机生成 xx-xx 之间的数
    name: Random.cname(), //名称
    image: Random.image('18x18', "#d8d8d8", '#fff', 'mock'),
    produtTime: Random.date() + ' ' + Random.time(),
    price: Random.natural(200, 500), //价格
    status: '正常',
    include: getInclude(), //所属栏目
  }
  productList.push(obj)
}
// 分页获取所有产品(按条件检索)
Mock.mock('/product/list', 'post', options => {
  // 按分页及条件进行查找
  let params = JSON.parse(options.body)
  let newArr = []
  const [pageSize, pageNum] = [params.pageSize, params.pageNum]
  // name 不为空
  if (params.name !== '') {
    if (params.status !== '') {
      if (params.include !== '') {
        newArr = productList.filter(x => x.status == params.status).filter(x => x.include == params.include).filter(x => x.name = params.name)
        if (newArr.length <= 0) {
          return {
            status: 2001,
            message: '未找到符合条件的数据'
          }
        }
      } else {
        newArr = productList.filter(x => x.status == params.status).filter(x => x.name == params.name)
        if (newArr.length <= 0) {
          return {
            status: 2001,
            message: '未找到符合条件的数据'
          }
        }
      }
    } else {
      if (params.include !== '') {
        newArr = productList.filter(x => x.name == params.name).filter(x => x.include == params.include)
        if (newArr.length <= 0) {
          return {
            status: 2001,
            message: '未找到符合条件的数据'
          }
        }
      } else {
        newArr = productList.filter(x => x.name == params.name)
        if (newArr.length <= 0) {
          return {
            status: 2001,
            message: '未找到符合条件的数据'
          }
        }
      }
    }
  }
  // name为空
  else {
    // status不为空
    if (params.status !== '') {
      // include 不为空
      if (params.include !== '') {
        newArr = productList.filter(x => x.status == params.status).filter(x => x.include == params.include)
        if (newArr.length <= 0) {
          return {
            status: 2000,
            message: '未找到符合条件的数据'
          }
        }
      }
      // include 为空
      else {
        newArr = productList.filter(x => x.status == params.status)
        if (newArr.length <= 0) {
          return {
            status: 2000,
            message: '未找到符合条件的数据'
          }
        }
      }
    }
    // status 为空
    else {
      if (params.include !== '') {
        newArr = productList.filter(x => x.include == params.include)
        if (newArr.length <= 0) {
          return {
            status: 2000,
            message: '未找到符合条件的数据'
          }
        }
      } else {
        newArr = productList
      }
    }
  }
  const newDatas = newArr.slice((pageNum - 1) * pageSize, pageNum * pageSize)
  return {
    status: 2000,
    data: newDatas,
    total: newArr.length,
    message: '成功'
  }
})
// 获取所有栏目的接口
Mock.mock('/product', 'get', options => {
  return {
    status: 2000,
    data: includeList,
    message: '成功'
  }
})

// 下架产品
Mock.mock('/product/tackdown', 'post', options => {
  let id = JSON.parse(options.body)
  for (let i = 0; i < productList.length; i++) {
    if (productList[i].id == id) {
      productList[i].status = '下架'
    }
  }
  return {
    status: 2000,
    message: '下架成功'
  }
})
// 上架产品
Mock.mock('/product/update', 'post', options => {
  let id = JSON.parse(options.body)
  for (let i = 0; i < productList.length; i++) {
    if (productList[i].id == id) {
      productList[i].status = '正常'
    }
  }
  return {
    status: 2000,
    message: '上架成功'
  }
})
// 编辑产品
Mock.mock('/product/edit', 'post', options => {
  let params = JSON.parse(options.body)
  const [id, name, price, status, include] = [params.id, params.name, params.price, params.status, params.include]
  for (let i = 0; i < productList.length; i++) {
    if (productList[i].id == id) {
      productList[i].name = name
      productList[i].price = price
      productList[i].status = status
      productList[i].include = include
    }
  }
  return {
    status: 2000,
    message: '更新成功'
  }
})
// 添加产品
Mock.mock('/product/addproduct', 'post', options => {
  let params = JSON.parse(options.body)
  const [name, price, status, include] = [params.name, params.price, params.status, params.include]
  let obj = {
    id: productList.length + 1,
    name: name,
    price: price,
    status: status,
    include: include,
    productNum: Random.natural(9000, 10000),
    image: Random.image('18x18', "#d8d8d8", '#fff', 'mock'),
    produtTime: Random.date() + ' ' + Random.time(), // 随机生成时间
  }
  productList.unshift(obj)
  return {
    status: 2000,
    message: '添加成功'
  }
})
//#endregion

// 审核大厅相关接口
//#region 
// 实名认证数据
let { auditData } = Mock.mock({
  //随机生成20-30条 数据 
  "auditData|20-30": [
    {
      "id|+1": 1, //id自增
      "appNum|+1": 500,
      "name": function () { return Random.cname() },
      "apptime": function () { return Random.datetime("yyyy-MM-dd HH:mm:ss") },
      "idNumber": function () { return Random.id() }, //生成身份证号码
      "idCardForword": Random.image('22x22', "#d8d8d8", '#fff', 'mock'),
      "idCardback": Random.image('22x22', "#d8d8d8", '#fff', 'mock'),
      "bankNum": "@idcard",//@idcard 生成身份证号(在此模拟生成银行卡号)
      "bankCard": function () { return Random.image('22x22', "#d8d8d8", '#fff', 'mock') },
      "status|1": ['通过', '不通过', '未审核']
    }
  ]
})
// 分页请求获取实名认证数据
Mock.mock('/certification/list', 'post', options => {
  const [pageSize, pageNum, total] = [JSON.parse(options.body).pageSize, JSON.parse(options.body).pageNum, auditData.length]
  // 截取auditData
  const newDatas = auditData.slice((pageNum - 1) * pageSize, pageNum * pageSize)
  return {
    status: 2000,
    message: '获取数据成功',
    data: newDatas,
    total: total
  }
})
// 通过审核接口
Mock.mock('/certification/pass', 'post', options => {
  let id = JSON.parse(options.body)
  for (let i = 0; i < auditData.length; i++) {
    if (auditData[i].id == id) {
      auditData[i].status = '通过'
    }
  }
  return {
    status: 2000,
    message: '审核通过'
  }
})
// 不通过审核
Mock.mock('/certification/notpass', 'post', options => {
  let id = JSON.parse(options.body)
  for (let i = 0; i < auditData.length; i++) {
    if (auditData[i].id == id) {
      auditData[i].status = '不通过'
    }
  }
  return {
    status: 2000,
    message: '操作成功'
  }
})

// 账户变更
// 账户变更数据
let { accountChangeDatas } = Mock.mock({
  //随机生成20-30条 数据
  "accountChangeDatas|20-30": [
    {
      "id|+1": 1, //id自增
      "appNum|+1": 500, //申请人编号
      "apptime": function () { return Random.datetime("yyyy-MM-dd HH:mm:ss") },
      "changeAmount": function () { return Random.natural(10, 50) },  //变更金额
      "changeType|1": ["提现", "充值", "转账"],
      "changeReason": function () { return Random.cword(8) }, //变更原因
      "status|1": ['通过', '不通过', '未审核']
    }
  ]
})
// 分页获取账户变更数据
Mock.mock('/accountChange/list', 'post', options => {
  const [pageSize, pageNum, total] = [JSON.parse(options.body).pageSize, JSON.parse(options.body).pageNum, accountChangeDatas.length]
  // 截取auditData
  const newDatas = accountChangeDatas.slice((pageNum - 1) * pageSize, pageNum * pageSize)
  return {
    status: 2000,
    message: '获取数据成功',
    data: newDatas,
    total: total
  }
})
// 账户变更审核--通过
Mock.mock('/accountChange/pass', 'post', options => {
  let id = JSON.parse(options.body)
  for (let i = 0; i < accountChangeDatas.length; i++) {
    if (accountChangeDatas[i].id == id) {
      accountChangeDatas[i].status = '通过'
    }
  }
  return {
    status: 2000,
    message: '审核通过'
  }
})
// 账户变更审核--不通过
Mock.mock('/accountChange/notpass', 'post', options => {
  let id = JSON.parse(options.body)
  for (let i = 0; i < accountChangeDatas.length; i++) {
    if (accountChangeDatas[i].id == id) {
      accountChangeDatas[i].status = '不通过'
    }
  }
  return {
    status: 2000,
    message: '操作成功'
  }
})

// 资讯评论
// 资讯评论数据
let { InformationDatas } = Mock.mock({
  "InformationDatas|2-5": [
    {
      "id|+1": 1,
      "infocontent": function () { return Random.paragraph(1) }, //评论内容--随机生成两个段落
      "personId|+1": 200,//评论人编号
      "informationId|+1": 300,//资讯编号
      "informationTime": function () { return Random.datetime("yyyy-MM-dd HH:mm:ss") },
      "status|1": ['通过', '不通过', '未审核']
    }
  ]
})
// 分页获取资讯评论数据
Mock.mock('/information/list', 'post', options => {
  const [pageSize, pageNum, total] = [JSON.parse(options.body).pageSize, JSON.parse(options.body).pageNum, InformationDatas.length]
  // 截取auditData
  const newDatas = InformationDatas.slice((pageNum - 1) * pageSize, pageNum * pageSize)
  return {
    status: 2000,
    message: '获取数据成功',
    data: newDatas,
    total: total
  }
})
// 通过评论
Mock.mock('/information/pass', 'post', options => {
  let id = JSON.parse(options.body)
  for (let i = 0; i < InformationDatas.length; i++) {
    if (InformationDatas[i].id == id) {
      InformationDatas[i].status = '通过'
    }
  }
  return {
    status: 2000,
    message: '审核通过'
  }
})
// 不通过评论
Mock.mock('/information/notpass', 'post', options => {
  let id = JSON.parse(options.body)
  for (let i = 0; i < InformationDatas.length; i++) {
    if (InformationDatas[i].id == id) {
      InformationDatas[i].status = '不通过'
    }
  }
  return {
    status: 2000,
    message: '操作成功'
  }
})
// 删除评论
Mock.mock('/information/pass', 'del', options => {
  let id = JSON.parse(options.body)
  InformationDatas = InformationDatas.filter(x => x.id !== id)
  return {
    status: 2000,
    message: '删除成功'
  }
})

// 订单评论
// 1.先给数据源
let { orderDatas } = Mock.mock({
  "orderDatas|5-10": [
    {
      "id|+1": 1,
      "orderContent": function () { return Random.word(20) }, //评论内容--随机生成两个段落
      "customId|+1": 200,//顾客编号
      "orderId|+1": 300,//订单编号
      "comTime": function () { return Random.datetime("yyyy-MM-dd HH:mm:ss") },
      "status|1": ['通过', '不通过', '未审核']
    }
  ]
})
// 2.分页获取数据
Mock.mock('/orderComment/list', 'post', options => {
  let params = JSON.parse(options.body)
  const [pageSize, pageNum, status, total] = [params.pageSize, params.pageNum, params.status, orderDatas.length]
  // 截取orderDatas
  let newArr = []
  // 当status不为空的时候
  if (status !== '') {
    newArr = orderDatas.filter(x => x.status == status)
  } else {
    newArr = orderDatas
  }
  const newDatas = newArr.slice((pageNum - 1) * pageSize, pageNum * pageSize)
  return {
    status: 2000,
    message: '获取数据成功',
    data: newDatas,
    total: total
  }
})
// 3.其他的接口 pass nopass del
Mock.mock('/orderComment/pass', 'post', options => {
  let id = JSON.parse(options.body)
  for (let i = 0; i < orderDatas.length; i++) {
    if (orderDatas[i].id == id) {
      orderDatas[i].status = '通过'
    }
  }
  return {
    status: 2000,
    message: '通过评论'
  }
})
Mock.mock('/orderComment/nopass', 'post', options => {
  let id = JSON.parse(options.body)
  for (let i = 0; i < orderDatas.length; i++) {
    if (orderDatas[i].id == id) {
      orderDatas[i].status = '不通过'
    }
  }
  return {
    status: 2000,
    message: '操作成功'
  }
})
Mock.mock('/orderComment/del', 'post', options => {
  let id = JSON.parse(options.body)
  orderDatas = orderDatas.filter(x => x.id !== id)  //js filter方法 （item,index）=>{}
  return {
    status: 2000,
    message: '删除成功'
  }
})
//#endregion


// 网站资讯相关接口
//#region 
// 资讯信息相关接口
let { informationMsgDatas } = Mock.mock({
  "informationMsgDatas|10-15": [
    {
      "id|+1": 1,
      "name": function () { return Random.cname() },
      "sortId|+1": 500,
      "discip": function () { return Random.paragraph(1) }
    }
  ]
})
// 分页请求资讯信息
Mock.mock('/inforMsg/list', 'post', options => {
  const [pageSize, pageNum, total] = [JSON.parse(options.body).pageSize, JSON.parse(options.body).pageNum, informationMsgDatas.length]
  // 截取auditData
  const newDatas = informationMsgDatas.slice((pageNum - 1) * pageSize, pageNum * pageSize)
  return {
    status: 2000,
    message: '获取数据成功',
    data: newDatas,
    total: total
  }
})
//#endregion


//#region 日志管理
// 数据源
let { logDatas } = Mock.mock({
  "logDatas|10-15": [
    {
      "id|+1": 1,
      "realName|1": [function () { return Random.cname() }, '杰普'],
      "visitMethod|1": ['get', 'post', 'del'], //访问方式
      "visitUrl": function () { return '/user/' + Random.word(2) },
      "time": function () { return Random.datetime("yyyy-MM-dd HH:mm:ss") }
    }
  ]
})
// 分页获取数据
Mock.mock('/log/list', 'post', options => {
  const [pageSize, pageNum, total] = [JSON.parse(options.body).pageSize, JSON.parse(options.body).pageNum, logDatas.length]
  // 截取
  const newDatas = logDatas.slice((pageNum - 1) * pageSize, pageNum * pageSize)
  return {
    status: 2000,
    message: '获取数据成功',
    data: newDatas,
    total: total
  }
})
//#endregion

//#region 轮播管理
// 轮播管理数据源
let imagNames = [
  'one',
  'two',
  'three',
  'four'
]
let carDatas = []
for (let i = 0; i < imagNames.length; i++) {
  let obj = {
    id: i + 1,
    carName: imagNames[i], //轮播图名称
    carDis: Random.paragraph(1), //描述
    carImg: Random.image('22x22', "#d8d8d8", '#fff', 'mock'),
    status: Random.pick(['正常', '停用'])
  }
  carDatas.push(obj)
}
// 获取轮播图数据
Mock.mock('/carousel/list', 'get', options => {
  return {
    status: 2000,
    data: carDatas,
    message: '成功'
  }
})
// 编辑

// 停用

// 启用


//#endregion
